#ifndef __AMBA_NET_H__
#define __AMBA_NET_H__

#include <stdio.h>

#include <string>

#ifdef __cplusplus
extern "C" {
  
#endif

#include "cvapi_ambacv_flexidag.h"
#include "cvapi_svccvalgo_memio_interface.h"

#ifdef __cplusplus
}
#endif

#ifndef Print
#define Print(str, arg...)	printf("%s, %s(%d): "  str, __FILE__, __func__, __LINE__, ##arg)
#endif

class AmbaNet {
 public:
  AmbaNet() noexcept;
  virtual ~AmbaNet() = default;

  AmbaNet(AmbaNet const&) = default;
  AmbaNet(AmbaNet&&) = default;
  AmbaNet &operator=(AmbaNet const &) = delete;
  AmbaNet &operator=(AmbaNet const &&) = delete;

  uint32_t LoadInPutFile(std::string const& input_path, int order,
                              memio_source_recv_multi_raw_t *raw,
                              flexidag_memblk_t *input_image_buf) noexcept;

  uint32_t LoadInPutBuffer(char *input_buffer, uint32_t buffer_size,
                                int order, memio_source_recv_multi_raw_t *raw,
                                flexidag_memblk_t *input_image_buf) noexcept;

  virtual std::uint32_t Init(std::string const &flexidag_path) noexcept;

  AMBA_CV_FLEXIDAG_IO_s& GetOutBuf() noexcept;
  std::uint32_t RunBlock() noexcept;
  std::uint32_t RunNonBlock(flexidag_cb call_back, void *cb_param,
                            std::uint32_t& token_id) noexcept;
  std::uint32_t WaitRunFinish(std::uint32_t token_id) noexcept;
  std::uint32_t alloc_IO_buffer() noexcept;
//  protected:
  
  std::uint32_t destory() noexcept;
  std::uint32_t input_done() noexcept;
  virtual std::uint32_t free_all_buffer() = 0;

  AMBA_CV_FLEXIDAG_HANDLE_s handle_;
  memio_source_recv_multi_raw_t raw_;
  //  memio_source_recv_multi_raw_t 
  //  memio_source_recv_raw_t
  AMBA_CV_FLEXIDAG_RUN_INFO_s run_info_;
  // memory blocks
  flexidag_memblk_t net_buf_;
  AMBA_CV_FLEXIDAG_IO_s in_buf_;
  AMBA_CV_FLEXIDAG_IO_s out_buf_;
  AMBA_CV_FLEXIDAG_INIT_s init;

private:
  bool inited_{false};
  bool isAllocated{false};
};

#endif